
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>django.views.debug &#8212; Django 2.2.12.dev20200304094918 documentation</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />



 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 2.2.12.dev20200304094918 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-views-debug">
            
  <h1>Source code for django.views.debug</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">types</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="k">import</span> <span class="n">Path</span>

<span class="kn">from</span> <span class="nn">django.conf</span> <span class="k">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">HttpResponse</span><span class="p">,</span> <span class="n">HttpResponseNotFound</span>
<span class="kn">from</span> <span class="nn">django.template</span> <span class="k">import</span> <span class="n">Context</span><span class="p">,</span> <span class="n">Engine</span><span class="p">,</span> <span class="n">TemplateDoesNotExist</span>
<span class="kn">from</span> <span class="nn">django.template.defaultfilters</span> <span class="k">import</span> <span class="n">pprint</span>
<span class="kn">from</span> <span class="nn">django.urls</span> <span class="k">import</span> <span class="n">Resolver404</span><span class="p">,</span> <span class="n">resolve</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="k">import</span> <span class="n">timezone</span>
<span class="kn">from</span> <span class="nn">django.utils.datastructures</span> <span class="k">import</span> <span class="n">MultiValueDict</span>
<span class="kn">from</span> <span class="nn">django.utils.encoding</span> <span class="k">import</span> <span class="n">force_text</span>
<span class="kn">from</span> <span class="nn">django.utils.module_loading</span> <span class="k">import</span> <span class="n">import_string</span>
<span class="kn">from</span> <span class="nn">django.utils.version</span> <span class="k">import</span> <span class="n">get_docs_version</span>

<span class="c1"># Minimal Django templates engine to render the error templates</span>
<span class="c1"># regardless of the project&#39;s TEMPLATES setting. Templates are</span>
<span class="c1"># read directly from the filesystem so that the error handler</span>
<span class="c1"># works even if the template loader is broken.</span>
<span class="n">DEBUG_ENGINE</span> <span class="o">=</span> <span class="n">Engine</span><span class="p">(</span>
    <span class="n">debug</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">libraries</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;i18n&#39;</span><span class="p">:</span> <span class="s1">&#39;django.templatetags.i18n&#39;</span><span class="p">},</span>
<span class="p">)</span>

<span class="n">HIDDEN_SETTINGS</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s1">&#39;API|TOKEN|KEY|SECRET|PASS|SIGNATURE&#39;</span><span class="p">,</span> <span class="n">flags</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">IGNORECASE</span><span class="p">)</span>

<span class="n">CLEANSED_SUBSTITUTE</span> <span class="o">=</span> <span class="s1">&#39;********************&#39;</span>

<span class="n">CURRENT_DIR</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span>


<span class="k">class</span> <span class="nc">CallableSettingWrapper</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object to wrap callable appearing in settings.</span>
<span class="sd">    * Not to call in the debug page (#21345).</span>
<span class="sd">    * Not to break the debug page if the callable forbidding to set attributes</span>
<span class="sd">      (#23070).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">callable_setting</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_wrapped</span> <span class="o">=</span> <span class="n">callable_setting</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_wrapped</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">cleanse_setting</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Cleanse an individual setting key/value of sensitive content. If the value</span>
<span class="sd">    is a dictionary, recursively cleanse the keys in that dictionary.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">HIDDEN_SETTINGS</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
            <span class="n">cleansed</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
                <span class="n">cleansed</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">cleanse_setting</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">value</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">cleansed</span> <span class="o">=</span> <span class="n">value</span>
    <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
        <span class="c1"># If the key isn&#39;t regex-able, just return as-is.</span>
        <span class="n">cleansed</span> <span class="o">=</span> <span class="n">value</span>

    <span class="k">if</span> <span class="n">callable</span><span class="p">(</span><span class="n">cleansed</span><span class="p">):</span>
        <span class="c1"># For fixing #21345 and #23070</span>
        <span class="n">cleansed</span> <span class="o">=</span> <span class="n">CallableSettingWrapper</span><span class="p">(</span><span class="n">cleansed</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">cleansed</span>


<span class="k">def</span> <span class="nf">get_safe_settings</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Return a dictionary of the settings module with values of sensitive</span>
<span class="sd">    settings replaced with stars (*********).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">settings_dict</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">dir</span><span class="p">(</span><span class="n">settings</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">k</span><span class="o">.</span><span class="n">isupper</span><span class="p">():</span>
            <span class="n">settings_dict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">cleanse_setting</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">settings_dict</span>


<span class="k">def</span> <span class="nf">technical_500_response</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tb</span><span class="p">,</span> <span class="n">status_code</span><span class="o">=</span><span class="mi">500</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a technical server error response. The last three arguments are</span>
<span class="sd">    the values returned from sys.exc_info() and friends.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">reporter</span> <span class="o">=</span> <span class="n">ExceptionReporter</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tb</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">is_ajax</span><span class="p">():</span>
        <span class="n">text</span> <span class="o">=</span> <span class="n">reporter</span><span class="o">.</span><span class="n">get_traceback_text</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status_code</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;text/plain; charset=utf-8&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">html</span> <span class="o">=</span> <span class="n">reporter</span><span class="o">.</span><span class="n">get_traceback_html</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">html</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status_code</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;text/html&#39;</span><span class="p">)</span>


<span class="nd">@functools</span><span class="o">.</span><span class="n">lru_cache</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">get_default_exception_reporter_filter</span><span class="p">():</span>
    <span class="c1"># Instantiate the default filter for the first time and cache it.</span>
    <span class="k">return</span> <span class="n">import_string</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">DEFAULT_EXCEPTION_REPORTER_FILTER</span><span class="p">)()</span>


<span class="k">def</span> <span class="nf">get_exception_reporter_filter</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">default_filter</span> <span class="o">=</span> <span class="n">get_default_exception_reporter_filter</span><span class="p">()</span>
    <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">&#39;exception_reporter_filter&#39;</span><span class="p">,</span> <span class="n">default_filter</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">ExceptionReporterFilter</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base for all exception reporter filter classes. All overridable hooks</span>
<span class="sd">    contain lenient default behaviors.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">get_post_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">request</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span>

    <span class="k">def</span> <span class="nf">get_traceback_frame_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">tb_frame</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>


<div class="viewcode-block" id="SafeExceptionReporterFilter"><a class="viewcode-back" href="../../../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter">[docs]</a><span class="k">class</span> <span class="nc">SafeExceptionReporterFilter</span><span class="p">(</span><span class="n">ExceptionReporterFilter</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Use annotations made by the sensitive_post_parameters and</span>
<span class="sd">    sensitive_variables decorators to filter out sensitive information.</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="SafeExceptionReporterFilter.is_active"><a class="viewcode-back" href="../../../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.is_active">[docs]</a>    <span class="k">def</span> <span class="nf">is_active</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This filter is to add safety in production environments (i.e. DEBUG</span>
<span class="sd">        is False). If DEBUG is True then your site is not safe anyway.</span>
<span class="sd">        This hook is provided as a convenience to easily activate or</span>
<span class="sd">        deactivate the filter on a per request basis.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span> <span class="ow">is</span> <span class="kc">False</span></div>

    <span class="k">def</span> <span class="nf">get_cleansed_multivaluedict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">multivaluedict</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Replace the keys in a MultiValueDict marked as sensitive with stars.</span>
<span class="sd">        This mitigates leaking sensitive POST parameters if something like</span>
<span class="sd">        request.POST[&#39;nonexistent_key&#39;] throws an exception (#21098).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sensitive_post_parameters</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">&#39;sensitive_post_parameters&#39;</span><span class="p">,</span> <span class="p">[])</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_active</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="ow">and</span> <span class="n">sensitive_post_parameters</span><span class="p">:</span>
            <span class="n">multivaluedict</span> <span class="o">=</span> <span class="n">multivaluedict</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">param</span> <span class="ow">in</span> <span class="n">sensitive_post_parameters</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">param</span> <span class="ow">in</span> <span class="n">multivaluedict</span><span class="p">:</span>
                    <span class="n">multivaluedict</span><span class="p">[</span><span class="n">param</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
        <span class="k">return</span> <span class="n">multivaluedict</span>

<div class="viewcode-block" id="SafeExceptionReporterFilter.get_post_parameters"><a class="viewcode-back" href="../../../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.get_post_parameters">[docs]</a>    <span class="k">def</span> <span class="nf">get_post_parameters</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Replace the values of POST parameters marked as sensitive with</span>
<span class="sd">        stars (*********).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">request</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sensitive_post_parameters</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">&#39;sensitive_post_parameters&#39;</span><span class="p">,</span> <span class="p">[])</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_active</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="ow">and</span> <span class="n">sensitive_post_parameters</span><span class="p">:</span>
                <span class="n">cleansed</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">sensitive_post_parameters</span> <span class="o">==</span> <span class="s1">&#39;__ALL__&#39;</span><span class="p">:</span>
                    <span class="c1"># Cleanse all parameters.</span>
                    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">cleansed</span><span class="p">:</span>
                        <span class="n">cleansed</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
                    <span class="k">return</span> <span class="n">cleansed</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="c1"># Cleanse only the specified parameters.</span>
                    <span class="k">for</span> <span class="n">param</span> <span class="ow">in</span> <span class="n">sensitive_post_parameters</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">param</span> <span class="ow">in</span> <span class="n">cleansed</span><span class="p">:</span>
                            <span class="n">cleansed</span><span class="p">[</span><span class="n">param</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
                    <span class="k">return</span> <span class="n">cleansed</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span></div>

    <span class="k">def</span> <span class="nf">cleanse_special_types</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># If value is lazy or a complex object of another kind, this check</span>
            <span class="c1"># might raise an exception. isinstance checks that lazy</span>
            <span class="c1"># MultiValueDicts will have a return value.</span>
            <span class="n">is_multivalue_dict</span> <span class="o">=</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">MultiValueDict</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">return</span> <span class="s1">&#39;</span><span class="si">{!r}</span><span class="s1"> while evaluating </span><span class="si">{!r}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">is_multivalue_dict</span><span class="p">:</span>
            <span class="c1"># Cleanse MultiValueDicts (request.POST is the one we usually care about)</span>
            <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cleansed_multivaluedict</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">value</span>

<div class="viewcode-block" id="SafeExceptionReporterFilter.get_traceback_frame_variables"><a class="viewcode-back" href="../../../howto/error-reporting.html#django.views.debug.SafeExceptionReporterFilter.get_traceback_frame_variables">[docs]</a>    <span class="k">def</span> <span class="nf">get_traceback_frame_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">tb_frame</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Replace the values of variables marked as sensitive with</span>
<span class="sd">        stars (*********).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Loop through the frame&#39;s callers to see if the sensitive_variables</span>
        <span class="c1"># decorator was used.</span>
        <span class="n">current_frame</span> <span class="o">=</span> <span class="n">tb_frame</span><span class="o">.</span><span class="n">f_back</span>
        <span class="n">sensitive_variables</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">while</span> <span class="n">current_frame</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">current_frame</span><span class="o">.</span><span class="n">f_code</span><span class="o">.</span><span class="n">co_name</span> <span class="o">==</span> <span class="s1">&#39;sensitive_variables_wrapper&#39;</span> <span class="ow">and</span>
                    <span class="s1">&#39;sensitive_variables_wrapper&#39;</span> <span class="ow">in</span> <span class="n">current_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="p">):</span>
                <span class="c1"># The sensitive_variables decorator was used, so we take note</span>
                <span class="c1"># of the sensitive variables&#39; names.</span>
                <span class="n">wrapper</span> <span class="o">=</span> <span class="n">current_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="p">[</span><span class="s1">&#39;sensitive_variables_wrapper&#39;</span><span class="p">]</span>
                <span class="n">sensitive_variables</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">wrapper</span><span class="p">,</span> <span class="s1">&#39;sensitive_variables&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
                <span class="k">break</span>
            <span class="n">current_frame</span> <span class="o">=</span> <span class="n">current_frame</span><span class="o">.</span><span class="n">f_back</span>

        <span class="n">cleansed</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_active</span><span class="p">(</span><span class="n">request</span><span class="p">)</span> <span class="ow">and</span> <span class="n">sensitive_variables</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">sensitive_variables</span> <span class="o">==</span> <span class="s1">&#39;__ALL__&#39;</span><span class="p">:</span>
                <span class="c1"># Cleanse all variables</span>
                <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="p">:</span>
                    <span class="n">cleansed</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># Cleanse specified variables</span>
                <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">sensitive_variables</span><span class="p">:</span>
                        <span class="n">value</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleanse_special_types</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
                    <span class="n">cleansed</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Potentially cleanse the request and any MultiValueDicts if they</span>
            <span class="c1"># are one of the frame variables.</span>
            <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">cleansed</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleanse_special_types</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_code</span><span class="o">.</span><span class="n">co_name</span> <span class="o">==</span> <span class="s1">&#39;sensitive_variables_wrapper&#39;</span> <span class="ow">and</span>
                <span class="s1">&#39;sensitive_variables_wrapper&#39;</span> <span class="ow">in</span> <span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="p">):</span>
            <span class="c1"># For good measure, obfuscate the decorated function&#39;s arguments in</span>
            <span class="c1"># the sensitive_variables decorator&#39;s frame, in case the variables</span>
            <span class="c1"># associated with those arguments were meant to be obfuscated from</span>
            <span class="c1"># the decorated function&#39;s frame.</span>
            <span class="n">cleansed</span><span class="p">[</span><span class="s1">&#39;func_args&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>
            <span class="n">cleansed</span><span class="p">[</span><span class="s1">&#39;func_kwargs&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">CLEANSED_SUBSTITUTE</span>

        <span class="k">return</span> <span class="n">cleansed</span><span class="o">.</span><span class="n">items</span><span class="p">()</span></div></div>


<span class="k">class</span> <span class="nc">ExceptionReporter</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Organize and coordinate reporting on exceptions.&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tb</span><span class="p">,</span> <span class="n">is_email</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">request</span> <span class="o">=</span> <span class="n">request</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">filter</span> <span class="o">=</span> <span class="n">get_exception_reporter_filter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span> <span class="o">=</span> <span class="n">exc_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span> <span class="o">=</span> <span class="n">exc_value</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tb</span> <span class="o">=</span> <span class="n">tb</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_email</span> <span class="o">=</span> <span class="n">is_email</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">template_info</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;template_debug&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">template_does_not_exist</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">postmortem</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="nf">get_traceback_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return a dictionary containing traceback information.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span> <span class="ow">and</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span><span class="p">,</span> <span class="n">TemplateDoesNotExist</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">template_does_not_exist</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">postmortem</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="o">.</span><span class="n">chain</span> <span class="ow">or</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">]</span>

        <span class="n">frames</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_traceback_frames</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">frame</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">frames</span><span class="p">):</span>
            <span class="k">if</span> <span class="s1">&#39;vars&#39;</span> <span class="ow">in</span> <span class="n">frame</span><span class="p">:</span>
                <span class="n">frame_vars</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">frame</span><span class="p">[</span><span class="s1">&#39;vars&#39;</span><span class="p">]:</span>
                    <span class="n">v</span> <span class="o">=</span> <span class="n">pprint</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
                    <span class="c1"># Trim large blobs of data</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">4096</span><span class="p">:</span>
                        <span class="n">v</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">… &lt;trimmed </span><span class="si">%d</span><span class="s1"> bytes string&gt;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4096</span><span class="p">],</span> <span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="p">))</span>
                    <span class="n">frame_vars</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
                <span class="n">frame</span><span class="p">[</span><span class="s1">&#39;vars&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">frame_vars</span>
            <span class="n">frames</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">frame</span>

        <span class="n">unicode_hint</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span> <span class="ow">and</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span><span class="p">,</span> <span class="ne">UnicodeError</span><span class="p">):</span>
            <span class="n">start</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;start&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">end</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;end&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">start</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">end</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">unicode_str</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">unicode_hint</span> <span class="o">=</span> <span class="n">force_text</span><span class="p">(</span>
                    <span class="n">unicode_str</span><span class="p">[</span><span class="nb">max</span><span class="p">(</span><span class="n">start</span> <span class="o">-</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span><span class="nb">min</span><span class="p">(</span><span class="n">end</span> <span class="o">+</span> <span class="mi">5</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">unicode_str</span><span class="p">))],</span>
                    <span class="s1">&#39;ascii&#39;</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="s1">&#39;replace&#39;</span>
                <span class="p">)</span>
        <span class="kn">from</span> <span class="nn">django</span> <span class="k">import</span> <span class="n">get_version</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">user_str</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">user_str</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="c1"># request.user may raise OperationalError if the database is</span>
                <span class="c1"># unavailable, for example.</span>
                <span class="n">user_str</span> <span class="o">=</span> <span class="s1">&#39;[unable to retrieve the current user]&#39;</span>

        <span class="n">c</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;is_email&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_email</span><span class="p">,</span>
            <span class="s1">&#39;unicode_hint&#39;</span><span class="p">:</span> <span class="n">unicode_hint</span><span class="p">,</span>
            <span class="s1">&#39;frames&#39;</span><span class="p">:</span> <span class="n">frames</span><span class="p">,</span>
            <span class="s1">&#39;request&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="p">,</span>
            <span class="s1">&#39;user_str&#39;</span><span class="p">:</span> <span class="n">user_str</span><span class="p">,</span>
            <span class="s1">&#39;filtered_POST_items&#39;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filter</span><span class="o">.</span><span class="n">get_post_parameters</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">()),</span>
            <span class="s1">&#39;settings&#39;</span><span class="p">:</span> <span class="n">get_safe_settings</span><span class="p">(),</span>
            <span class="s1">&#39;sys_executable&#39;</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">executable</span><span class="p">,</span>
            <span class="s1">&#39;sys_version_info&#39;</span><span class="p">:</span> <span class="s1">&#39;</span><span class="si">%d</span><span class="s1">.</span><span class="si">%d</span><span class="s1">.</span><span class="si">%d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">],</span>
            <span class="s1">&#39;server_time&#39;</span><span class="p">:</span> <span class="n">timezone</span><span class="o">.</span><span class="n">now</span><span class="p">(),</span>
            <span class="s1">&#39;django_version_info&#39;</span><span class="p">:</span> <span class="n">get_version</span><span class="p">(),</span>
            <span class="s1">&#39;sys_path&#39;</span><span class="p">:</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="p">,</span>
            <span class="s1">&#39;template_info&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">template_info</span><span class="p">,</span>
            <span class="s1">&#39;template_does_not_exist&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">template_does_not_exist</span><span class="p">,</span>
            <span class="s1">&#39;postmortem&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">postmortem</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;request_GET_items&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;request_FILES_items&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">FILES</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;request_COOKIES_items&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">COOKIES</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
        <span class="c1"># Check whether exception info is available</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span><span class="p">:</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;exception_type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_type</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">:</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;exception_value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">frames</span><span class="p">:</span>
            <span class="n">c</span><span class="p">[</span><span class="s1">&#39;lastframe&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">frames</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">c</span>

    <span class="k">def</span> <span class="nf">get_traceback_html</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return HTML version of debug 500 HTTP error page.&quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">Path</span><span class="p">(</span><span class="n">CURRENT_DIR</span><span class="p">,</span> <span class="s1">&#39;templates&#39;</span><span class="p">,</span> <span class="s1">&#39;technical_500.html&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
            <span class="n">t</span> <span class="o">=</span> <span class="n">DEBUG_ENGINE</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">Context</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_traceback_data</span><span class="p">(),</span> <span class="n">use_l10n</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">t</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_traceback_text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return plain text version of debug 500 HTTP error page.&quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="n">Path</span><span class="p">(</span><span class="n">CURRENT_DIR</span><span class="p">,</span> <span class="s1">&#39;templates&#39;</span><span class="p">,</span> <span class="s1">&#39;technical_500.txt&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
            <span class="n">t</span> <span class="o">=</span> <span class="n">DEBUG_ENGINE</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">Context</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_traceback_data</span><span class="p">(),</span> <span class="n">autoescape</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">use_l10n</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">t</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_lines_from_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">lineno</span><span class="p">,</span> <span class="n">context_lines</span><span class="p">,</span> <span class="n">loader</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">module_name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return context_lines before and after lineno from file.</span>
<span class="sd">        Return (pre_context_lineno, pre_context, context_line, post_context).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">source</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">loader</span><span class="p">,</span> <span class="s1">&#39;get_source&#39;</span><span class="p">):</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">source</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">get_source</span><span class="p">(</span><span class="n">module_name</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
                <span class="k">pass</span>
            <span class="k">if</span> <span class="n">source</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">source</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">source</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
                    <span class="n">source</span> <span class="o">=</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
            <span class="k">except</span> <span class="p">(</span><span class="ne">OSError</span><span class="p">,</span> <span class="ne">IOError</span><span class="p">):</span>
                <span class="k">pass</span>
        <span class="k">if</span> <span class="n">source</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span><span class="p">,</span> <span class="p">[],</span> <span class="kc">None</span><span class="p">,</span> <span class="p">[]</span>

        <span class="c1"># If we just read the source from a file, or if the loader did not</span>
        <span class="c1"># apply tokenize.detect_encoding to decode the source into a</span>
        <span class="c1"># string, then we should do that ourselves.</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">bytes</span><span class="p">):</span>
            <span class="n">encoding</span> <span class="o">=</span> <span class="s1">&#39;ascii&#39;</span>
            <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">source</span><span class="p">[:</span><span class="mi">2</span><span class="p">]:</span>
                <span class="c1"># File coding may be specified. Match pattern from PEP-263</span>
                <span class="c1"># (https://www.python.org/dev/peps/pep-0263/)</span>
                <span class="n">match</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">br</span><span class="s1">&#39;coding[:=]\s*([-\w.]+)&#39;</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">match</span><span class="p">:</span>
                    <span class="n">encoding</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;ascii&#39;</span><span class="p">)</span>
                    <span class="k">break</span>
            <span class="n">source</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">sline</span><span class="p">,</span> <span class="n">encoding</span><span class="p">,</span> <span class="s1">&#39;replace&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">sline</span> <span class="ow">in</span> <span class="n">source</span><span class="p">]</span>

        <span class="n">lower_bound</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">lineno</span> <span class="o">-</span> <span class="n">context_lines</span><span class="p">)</span>
        <span class="n">upper_bound</span> <span class="o">=</span> <span class="n">lineno</span> <span class="o">+</span> <span class="n">context_lines</span>

        <span class="n">pre_context</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="n">lower_bound</span><span class="p">:</span><span class="n">lineno</span><span class="p">]</span>
        <span class="n">context_line</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="n">lineno</span><span class="p">]</span>
        <span class="n">post_context</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="n">lineno</span> <span class="o">+</span> <span class="mi">1</span><span class="p">:</span><span class="n">upper_bound</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">lower_bound</span><span class="p">,</span> <span class="n">pre_context</span><span class="p">,</span> <span class="n">context_line</span><span class="p">,</span> <span class="n">post_context</span>

    <span class="k">def</span> <span class="nf">get_traceback_frames</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">def</span> <span class="nf">explicit_or_implicit_cause</span><span class="p">(</span><span class="n">exc_value</span><span class="p">):</span>
            <span class="n">explicit</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;__cause__&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="n">implicit</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;__context__&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">explicit</span> <span class="ow">or</span> <span class="n">implicit</span>

        <span class="c1"># Get the exception and all its causes</span>
        <span class="n">exceptions</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">exc_value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">exc_value</span>
        <span class="k">while</span> <span class="n">exc_value</span><span class="p">:</span>
            <span class="n">exceptions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">exc_value</span><span class="p">)</span>
            <span class="n">exc_value</span> <span class="o">=</span> <span class="n">explicit_or_implicit_cause</span><span class="p">(</span><span class="n">exc_value</span><span class="p">)</span>

        <span class="n">frames</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># No exceptions were supplied to ExceptionReporter</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">exceptions</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">frames</span>

        <span class="c1"># In case there&#39;s just one exception, take the traceback from self.tb</span>
        <span class="n">exc_value</span> <span class="o">=</span> <span class="n">exceptions</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
        <span class="n">tb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tb</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">exceptions</span> <span class="k">else</span> <span class="n">exc_value</span><span class="o">.</span><span class="n">__traceback__</span>

        <span class="k">while</span> <span class="n">tb</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># Support for __traceback_hide__ which is used by a few libraries</span>
            <span class="c1"># to hide internal frames.</span>
            <span class="k">if</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;__traceback_hide__&#39;</span><span class="p">):</span>
                <span class="n">tb</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_next</span>
                <span class="k">continue</span>
            <span class="n">filename</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_code</span><span class="o">.</span><span class="n">co_filename</span>
            <span class="n">function</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_code</span><span class="o">.</span><span class="n">co_name</span>
            <span class="n">lineno</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_lineno</span> <span class="o">-</span> <span class="mi">1</span>
            <span class="n">loader</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_globals</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;__loader__&#39;</span><span class="p">)</span>
            <span class="n">module_name</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="o">.</span><span class="n">f_globals</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;__name__&#39;</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">&#39;&#39;</span>
            <span class="n">pre_context_lineno</span><span class="p">,</span> <span class="n">pre_context</span><span class="p">,</span> <span class="n">context_line</span><span class="p">,</span> <span class="n">post_context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_lines_from_file</span><span class="p">(</span>
                <span class="n">filename</span><span class="p">,</span> <span class="n">lineno</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="n">loader</span><span class="p">,</span> <span class="n">module_name</span><span class="p">,</span>
            <span class="p">)</span>
            <span class="k">if</span> <span class="n">pre_context_lineno</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">pre_context_lineno</span> <span class="o">=</span> <span class="n">lineno</span>
                <span class="n">pre_context</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">context_line</span> <span class="o">=</span> <span class="s1">&#39;&lt;source code not available&gt;&#39;</span>
                <span class="n">post_context</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">frames</span><span class="o">.</span><span class="n">append</span><span class="p">({</span>
                <span class="s1">&#39;exc_cause&#39;</span><span class="p">:</span> <span class="n">explicit_or_implicit_cause</span><span class="p">(</span><span class="n">exc_value</span><span class="p">),</span>
                <span class="s1">&#39;exc_cause_explicit&#39;</span><span class="p">:</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">exc_value</span><span class="p">,</span> <span class="s1">&#39;__cause__&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">),</span>
                <span class="s1">&#39;tb&#39;</span><span class="p">:</span> <span class="n">tb</span><span class="p">,</span>
                <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;django&#39;</span> <span class="k">if</span> <span class="n">module_name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;django.&#39;</span><span class="p">)</span> <span class="k">else</span> <span class="s1">&#39;user&#39;</span><span class="p">,</span>
                <span class="s1">&#39;filename&#39;</span><span class="p">:</span> <span class="n">filename</span><span class="p">,</span>
                <span class="s1">&#39;function&#39;</span><span class="p">:</span> <span class="n">function</span><span class="p">,</span>
                <span class="s1">&#39;lineno&#39;</span><span class="p">:</span> <span class="n">lineno</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
                <span class="s1">&#39;vars&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">filter</span><span class="o">.</span><span class="n">get_traceback_frame_variables</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="p">,</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_frame</span><span class="p">),</span>
                <span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="nb">id</span><span class="p">(</span><span class="n">tb</span><span class="p">),</span>
                <span class="s1">&#39;pre_context&#39;</span><span class="p">:</span> <span class="n">pre_context</span><span class="p">,</span>
                <span class="s1">&#39;context_line&#39;</span><span class="p">:</span> <span class="n">context_line</span><span class="p">,</span>
                <span class="s1">&#39;post_context&#39;</span><span class="p">:</span> <span class="n">post_context</span><span class="p">,</span>
                <span class="s1">&#39;pre_context_lineno&#39;</span><span class="p">:</span> <span class="n">pre_context_lineno</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
            <span class="p">})</span>

            <span class="c1"># If the traceback for current exception is consumed, try the</span>
            <span class="c1"># other exception.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_next</span> <span class="ow">and</span> <span class="n">exceptions</span><span class="p">:</span>
                <span class="n">exc_value</span> <span class="o">=</span> <span class="n">exceptions</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
                <span class="n">tb</span> <span class="o">=</span> <span class="n">exc_value</span><span class="o">.</span><span class="n">__traceback__</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">tb</span> <span class="o">=</span> <span class="n">tb</span><span class="o">.</span><span class="n">tb_next</span>

        <span class="k">return</span> <span class="n">frames</span>


<span class="k">def</span> <span class="nf">technical_404_response</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Create a technical 404 error response. `exception` is the Http404.&quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">error_url</span> <span class="o">=</span> <span class="n">exception</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;path&#39;</span><span class="p">]</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">IndexError</span><span class="p">,</span> <span class="ne">TypeError</span><span class="p">,</span> <span class="ne">KeyError</span><span class="p">):</span>
        <span class="n">error_url</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">path_info</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>  <span class="c1"># Trim leading slash</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">tried</span> <span class="o">=</span> <span class="n">exception</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;tried&#39;</span><span class="p">]</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">IndexError</span><span class="p">,</span> <span class="ne">TypeError</span><span class="p">,</span> <span class="ne">KeyError</span><span class="p">):</span>
        <span class="n">tried</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="n">tried</span> <span class="ow">or</span> <span class="p">(</span>                  <span class="c1"># empty URLconf</span>
            <span class="n">request</span><span class="o">.</span><span class="n">path</span> <span class="o">==</span> <span class="s1">&#39;/&#39;</span> <span class="ow">and</span>
            <span class="nb">len</span><span class="p">(</span><span class="n">tried</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span>             <span class="c1"># default URLconf</span>
            <span class="nb">len</span><span class="p">(</span><span class="n">tried</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span>
            <span class="nb">getattr</span><span class="p">(</span><span class="n">tried</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;app_name&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">tried</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;namespace&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;admin&#39;</span>
        <span class="p">)):</span>
            <span class="k">return</span> <span class="n">default_urlconf</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>

    <span class="n">urlconf</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">&#39;urlconf&#39;</span><span class="p">,</span> <span class="n">settings</span><span class="o">.</span><span class="n">ROOT_URLCONF</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">urlconf</span><span class="p">,</span> <span class="n">types</span><span class="o">.</span><span class="n">ModuleType</span><span class="p">):</span>
        <span class="n">urlconf</span> <span class="o">=</span> <span class="n">urlconf</span><span class="o">.</span><span class="vm">__name__</span>

    <span class="n">caller</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">resolver_match</span> <span class="o">=</span> <span class="n">resolve</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">Resolver404</span><span class="p">:</span>
        <span class="k">pass</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">obj</span> <span class="o">=</span> <span class="n">resolver_match</span><span class="o">.</span><span class="n">func</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s1">&#39;__name__&#39;</span><span class="p">):</span>
            <span class="n">caller</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s1">&#39;__class__&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="vm">__class__</span><span class="p">,</span> <span class="s1">&#39;__name__&#39;</span><span class="p">):</span>
            <span class="n">caller</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="s1">&#39;__module__&#39;</span><span class="p">):</span>
            <span class="n">module</span> <span class="o">=</span> <span class="n">obj</span><span class="o">.</span><span class="vm">__module__</span>
            <span class="n">caller</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">.</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">module</span><span class="p">,</span> <span class="n">caller</span><span class="p">)</span>

    <span class="k">with</span> <span class="n">Path</span><span class="p">(</span><span class="n">CURRENT_DIR</span><span class="p">,</span> <span class="s1">&#39;templates&#39;</span><span class="p">,</span> <span class="s1">&#39;technical_404.html&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">open</span><span class="p">()</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="n">DEBUG_ENGINE</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">Context</span><span class="p">({</span>
        <span class="s1">&#39;urlconf&#39;</span><span class="p">:</span> <span class="n">urlconf</span><span class="p">,</span>
        <span class="s1">&#39;root_urlconf&#39;</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">ROOT_URLCONF</span><span class="p">,</span>
        <span class="s1">&#39;request_path&#39;</span><span class="p">:</span> <span class="n">error_url</span><span class="p">,</span>
        <span class="s1">&#39;urlpatterns&#39;</span><span class="p">:</span> <span class="n">tried</span><span class="p">,</span>
        <span class="s1">&#39;reason&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">exception</span><span class="p">),</span>
        <span class="s1">&#39;request&#39;</span><span class="p">:</span> <span class="n">request</span><span class="p">,</span>
        <span class="s1">&#39;settings&#39;</span><span class="p">:</span> <span class="n">get_safe_settings</span><span class="p">(),</span>
        <span class="s1">&#39;raising_view_name&#39;</span><span class="p">:</span> <span class="n">caller</span><span class="p">,</span>
    <span class="p">})</span>
    <span class="k">return</span> <span class="n">HttpResponseNotFound</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;text/html&#39;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">default_urlconf</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Create an empty URLconf 404 error response.&quot;&quot;&quot;</span>
    <span class="k">with</span> <span class="n">Path</span><span class="p">(</span><span class="n">CURRENT_DIR</span><span class="p">,</span> <span class="s1">&#39;templates&#39;</span><span class="p">,</span> <span class="s1">&#39;default_urlconf.html&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">open</span><span class="p">()</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="n">DEBUG_ENGINE</span><span class="o">.</span><span class="n">from_string</span><span class="p">(</span><span class="n">fh</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">Context</span><span class="p">({</span>
        <span class="s1">&#39;version&#39;</span><span class="p">:</span> <span class="n">get_docs_version</span><span class="p">(),</span>
    <span class="p">})</span>

    <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">c</span><span class="p">),</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;text/html&#39;</span><span class="p">)</span>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Mar 04, 2020</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>